package com.boarsoft.boar.sys.action;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.boarsoft.bean.LogonI;
import com.boarsoft.bean.ReplyInfo;
import com.boarsoft.boar.sys.SysPowerBiz;
import com.boarsoft.boar.sys.SysSmsBiz;
import com.boarsoft.boar.sys.entity.SysSms;
import com.boarsoft.common.Authorized;
import com.boarsoft.common.dao.PagedResult;
import com.boarsoft.common.util.JsonUtil;
import com.boarsoft.web.login.Logined;

@RestController
@RequestMapping("/sys/sms")
public class SysSmsAction {
	@Autowired
	SysSmsBiz sysSmsBiz;

	@Autowired
	SysPowerBiz sysPowerBiz;

	/**
	 * 查询未查看的消息数
	 * 
	 * @return
	 */
	@RequestMapping("/count.do")
	@Authorized(code = "sys.sms.count")
	public ReplyInfo<Object> list(@Logined LogonI<String> logon) {
		int count = sysSmsBiz.count(logon.getId());
		return new ReplyInfo<Object>(true, String.valueOf(count));
	}

	/**
	 * 查询当前用户所有消息
	 * 
	 * @return
	 */
	@RequestMapping("/list.do")
	@Authorized(code = "sys.sms.list")
	public ReplyInfo<String> findAll(@Logined LogonI<String> logon, int pageNo, int pageSize) {
		PagedResult<SysSms> pr = sysSmsBiz.list(logon.getId(), pageNo, pageSize);
		return new ReplyInfo<String>(true, JsonUtil.from(pr));
	}

	/**
	 * 将消息状态修改为已读
	 */
	@RequestMapping("/update.do")
	@Authorized(code = "sys.sms.update")
	public void update(String smsId) {
		sysSmsBiz.update(smsId);
	}
}
